<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>添加商家</title>
		<link rel="stylesheet" href="__AGENT__/css/css.css" />
		<script type="text/javascript" src="__PUBLIC__/static/js/jquery.min.js"></script>
		<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
		<script src="__PUBLIC__/static/layui/layui.js"></script>
	</head>

	<body>
		<form id="my_form" class="layui-form update_form" method="post">
			<div class="layui-form-item">
				<label class="layui-form-label">商铺名称</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="agent_name" lay-verify="required" placeholder="商铺名称" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item update_scbtn">
				<label class="layui-form-label">上传logo</label>
				<div class="layui-upload">
					<button type="button" class="layui-btn" id="test1">上传logo</button>
					<div class="layui-upload-list" style="    margin-left: 10%;">
						<img class="layui-upload-img" id="demo1" style="width: 200px;height: 200px;margin-left:100px;">
						<p id="demoText"></p>
					</div>
				</div>
				<input type="hidden" name='thumb' id='thumb' />
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">联系人</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="user_name" lay-verify="required" placeholder="联系人" autocomplete="off" class="layui-input">
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">联系电话</label>
				<div class="layui-input-block update_shurk">
					<input type="text" name="mobile" lay-verify="required" placeholder="联系电话" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">店铺性质</label>
				<div class="layui-input-block" style="float: left; margin-right: 20px; margin-left: 0;">
					<select name="store_property" id='store_property' lay-verify="required" lay-filter="sel_1">
						<option value=1>个人</option>
						<option value=2>企业</option>
						<option value=3>个体户</option>
					</select>
				</div>

			</div>
			<div class="layui-form-item update_btnbox" style="text-align: center;margin-left:unset">
				<div class="layui-input-block" style="    max-width: unset;float: unset;">
					<button type="button" lay-submit class="layui-btn" lay-filter="demo1">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</body>

</html>
<script type="text/javascript" src="__PUBLIC__/static/release/wangEditor.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/static/js/assist.js"></script>
<script>
	function add_agent() {
		$.ajax({
			type: "post",
			url: "{:url('oem/accounts/add_agent')}",
			data: $('#my_form').serialize(), //表单数据
			success: function(data) {
				if(data.code == 200) {
					layer.msg('添加成功', {
						icon: 1,
						time: 1500 //2秒关闭（如果不配置，默认是3秒）
					}, function() {
						window.parent.location.reload();
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
						parent.layer.close(index);
					});
				} else {
					layer.msg(data.msg); //保存成功提示
				}
			},
			error: function(data) {
				var a = data;
			}
		});

	}
	//图片上传
	layui.use(['form', 'upload'], function() {
		var $ = layui.jquery,
			upload = layui.upload,
			form = layui.form;

		//普通图片上传
		var uploadInst = upload.render({
			elem: '#test1',
			auto: false //选择文件后不自动上传
				,
			choose: function(obj) {
				//将每次选择的文件追加到文件队列
				var files = obj.pushFile();

				//预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
				obj.preview(function(index, file, result) {
					$('#demo1').attr('src', result); //图片链接（base64）
					var sendData = result.substring(result.indexOf(";base64,") + 8);
					$.post("{:url('oem/accounts/upload')}", {
						value: sendData
					}, function(data) {
						if(data.code == '200') {
							$('#thumb').val(data.url);
						} else {
							console.log(data);
						}
					});
				});
			},
			url: "{:url('oem/accounts/upload')}",
			accept: 'images'
		});
		//监听提交
		form.on('submit(demo1)', function(data) {
			add_agent();
			return false;
		});
	})
</script>